<template>
	<view class="page-container">
		
		<address-item style="margin-bottom: 20rpx;" :type="type" @select="selectAddress" />
		
		<!-- 底部提交按钮 -->
		<bottom-btn-bar v-if="type === 'manage'" text="新增地址" :isFixed="true" :isPlaceholder="true" @click="addAddress" />
		<bottom-btn-bar v-if="type === 'picker'" text="确认" :isFixed="true" :isPlaceholder="true" @click="pickerAddress" />
	</view>
</template>

<script>
	import addressItem from '@/components/addressItem/addressItem.vue';
	import bottomBtnBar from '@/components/bottomBtnBar/bottomBtnBar.vue';
	
	export default {
		components: {
			addressItem,
			bottomBtnBar
		},
		data() {
			return {
				type: 'manage', // manage：地址管理 picker：地址选择
				selectItem: null,
				list: []
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type;
			}
			uni.setNavigationBarTitle({
				title: this.type === 'picker' ? '地址选择' : '地址管理'
			});
		},
		onReachBottom() {
			
		},
		methods: {
			addAddress() {
				uni.navigateTo({
					url: '/pages/content/addUpdate/addUpdate'
				})
			},
			// 选择地址
			pickerAddress() {
				if (!this.selectItem) {
					uni.showToast({
						title: '请先选择一个地址',
						icon: 'none'
					})
					return;
				}
				this.getOpenerEventChannel().emit('pickerAddress', {data: this.selectItem});
				uni.navigateBack();
			},
			selectAddress(res) {
				console.log('---- selectAddress ----:', res);
				this.selectItem = res;
			}
		}
	}
</script>

<style>
	page{
		width: 100%;
		height: 100%;
	}
</style>
<style lang="scss" scoped>
.page-container{
	width: 100%;
	display: flex;
	flex-direction: column;
	min-height: 100%;
	padding: 32rpx;
	box-sizing: border-box;
	background-color: #F5F5F5;
}

</style>
